import os
import sys

from moviepy.audio.io.AudioFileClip import AudioFileClip


def get_all_videos():
    # work_path = os.path.dirname(os.path.realpath(sys.argv[0]))
    #
    # video_path = os.path.join(work_path, "Downloaded")

    video_path = '/Users/thyme/temp/douyin-downloader/Downloaded'

    # audio_path = os.path.join(work_path, "audio")
    # if not os.path.exists(audio_path):
    #     os.mkdir(audio_path)

    for dir_name, _, file_names in os.walk(video_path):
        # print(dir_name, "===", file_names)
        for name in file_names:
            if name.endswith(".mp4"):
                print(dir_name, name)
                file = os.path.join(dir_name, name)

                audio_file = dir_name + os.sep + name[:-4] + ".wav"

                audio_clip = AudioFileClip(file)
                print(audio_clip)
                audio_clip.write_audiofile(audio_file)


if __name__ == '__main__':
    get_all_videos()
